package com.lims;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @author limaosheng
 * @create 2024-04-01 14:43
 * @desc
 */
public class 手动分页例子 {
    public static void main(String[] args) {
        //待分页列表
        List<Integer> testList = new ArrayList<>();
        for(int i = 0;i < 156 ; i++){
            testList.add(i);
        }
        //计算页数
        int pageSize = 11 ;
        Integer pages = testList.size() / pageSize;
        if (testList.size() % pageSize != 0) {
            pages = pages + 1;
        }
        //获取每页记录
        for(int i = 1 ;i <= pages; i++){
            int start = (i-1) * pageSize;
            int end = i * pageSize;
            if(i == pages){
                end = testList.size();
            }
            List<Integer> subList = testList.subList(start,end);
            System.out.println("第" + i + "页：" + JSONObject.toJSONString(subList));
        }

    }
}
